<?php
$posts = $args['posts'] ?? [];
if (empty($posts)) {
    $posts = get_random_posts(6);
}
?>
<div class="ctimgpost3">
    <section class="imgpost3">
        <?php
        foreach ($posts as $post) {
        ?>
            <a href="<?= $post['link'] ?>" title="<?= $post['title'] ?>">
                <img src="<?= $post['thumbnail'] ?>" alt="<?= $post['title'] ?>">
                <section class="grid">
                    <h3 class="nowrap2"><?= $post['title'] ?></h3>
                </section>
            </a>
        <?php
        }
        ?>
    </section>
</div>
<style>
    :root{
        --border-radius: 0;
        --color-primary:#343b2e;
    }
    div.ctimgpost3 {
        container-type: inline-size;
        container-name: imgpost3;
    }

    section.imgpost3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: var(--gap);
    }

    section.imgpost3>a {
        transition: var(--transition);
        background-color: var(--color-primary);
    }
    section.imgpost3>a>img {
        width: 100%;
        height: 90%;
    }


    section.imgpost3>a:nth-child(3){
        grid-column: 2/4;
        grid-row: 1/3;
    }
    section.imgpost3>a:nth-child(3)>img{
        height: 90%; 
        max-height: 30rem;
    }

    section.imgpost3>a>section {
        padding: var(--gap);
    }

    section.imgpost3>a>img,
    section.imgpost3>a>section>h3,
    section.imgpost3>a>section>span,
    section.imgpost3>a>section>p {
        cursor: pointer;
    }

    section.imgpost3>a:hover {
        transform: scale(1.05);
        filter: brightness(1.2);
        border: 1px solid #ffbd41;
        box-shadow: 0px 4px 6px rgb(255, 189, 65, .2);
    }

    @container imgpost3 (max-width: 1200px) {
        section.imgpost3 {
            grid-template-columns: repeat(3, 1fr);
        }

        section.imgpost3>a>img {
            height: 12rem;
        }

    }

    @container imgpost3 (max-width: 1024px) {
        section.imgpost3 {
            grid-template-columns: repeat(3, 1fr);
        }
      
        section.imgpost3>a>img {
            height: 12rem;
        }
        section.imgpost3>a:nth-child(3)>img{
            height: 12rem;
        }
        section.imgpost3>a:nth-child(3){
            grid-column: auto;
            grid-row: auto;
            
        }
    }

    @container imgpost3 (max-width: 768px) {
        section.imgpost3 {
            grid-template-columns: repeat(2, 1fr);
        }
    }


    @container imgpost3 (max-width: 576px) {
        section.imgpost3 {
            grid-template-columns: auto;
        }

        section.imgpost3>a>img {
            height: 16rem;
        }
    }
</style>